package com.ylesb.ioc;
/**
 * @title: Main
 * @projectName springdemo
 * @description: TODO
 * @author White
 * @site : [www.ylesb.com]
 * @date 2022/7/614:51
 */

import com.ylesb.ioc.model.User;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

/**
 * @className    : Main
 * @description  : [描述说明该类的功能]  
 * @author       : [XuGuangchao]
 * @site         : [www.ylesb.com]
 * @version      : [v1.0]
 * @createTime   : [2022/7/6 14:51]
 * @updateUser   : [XuGuangchao]
 * @updateTime   : [2022/7/6 14:51]
 * @updateRemark : [描述说明本次修改内容] 
 */

public class Main {
    public static void main(String[] args) {
        //FileSystemXmlApplicationContext fileSystemXmlApplicationContext = new FileSystemXmlApplicationContext(new ClassPathXmlApplicationContext("绝对路径"));
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        //method1(ctx);
        //method2(ctx);
        User user4 = ctx.getBean("user4", User.class);
        System.out.println("user4 = " + user4);

    }
    public static void method1(ClassPathXmlApplicationContext ctx)
    {
        User user1 = (User) ctx.getBean("user");
        User user2 = ctx.getBean("user", User.class);
        User user3 = ctx.getBean(User.class);
        System.out.println("user1 = " + user1);
        System.out.println("user2 = " + user2);
        System.out.println("user3 = " + user3);
    }
    public static void method2(ClassPathXmlApplicationContext ctx)
    {
        User user1 = (User) ctx.getBean("user");
        User user2 = ctx.getBean("user2", User.class);
        System.out.println("user1 = " + user1);
        System.out.println("user2 = " + user2);
    }
}
